var app   = getApp()
Page({
  data:{
    list:[],
    page:0,
    imageurl:'http://www.shsytour.cn/'
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    console.log(options);
    this.setData({
      page: options.page,
      area: options.area,
      sdate: options.sdate,
      edate: options.edate,
    })
    this.getList(options.area, options.sdate, options.edate)
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  onReachBottom:function(){
    this.getList(this.data.area, this.data.sdate, this.data.edate);
  },
  onPullDownRefresh: function(){
    this.getList(this.data.area, this.data.sdate, this.data.edate);
    wx.stopPullDownRefresh()
  },
  getList:function(area, sdate, edate){
    var that = this
    app.getJson('wxapp/search',{'area':area,'sdate':sdate,'edate':edate, 'page': this.data.page},function(res){
      if (res.data.code == 200) {
        if (res.data.data.length) {
          var page = parseInt(that.data.page) + 1
          console.log(res.data.data)
          var list = res.data.data.concat(that.data.list);
          that.setData({
            page: page,
            list:list
          })

        }else{
          wx.showToast({
            title: '到底了',
            icon: 'success',
            duration: 2000
          })
        }
        
      }else{
        wx.showModal({
          title: '提示',
          content: res.data.message,
          showCancel: false
        })
      }
      wx.hideToast()
    })
  }
})